#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <termios.h>

#define BUF_SIZE 256

void test_read_write( void )
{
	char buf[BUF_SIZE];
	size_t count;

	while((count = read( STDIN_FILENO, buf, BUF_SIZE )) > 0 ) {
		write( STDIN_FILENO, buf, count );
	}
}

int main( int argc, char *argv[] )
{
	struct termios term;
	long vdisable;

	// if not a terminal, exit
	if( !isatty( STDIN_FILENO ) ) {
		fprintf( stderr, "standard input is not a terminal device.\n" );
		exit( 0 );
	}

	if( (vdisable = fpathconf( STDIN_FILENO, _PC_VDISABLE ) ) < 0 ) {
		fprintf( stderr, "fpathconf error or _POSIX_VDISABLE not in errect.\n" );
		exit( 0 );
	}

	if( tcgetattr( STDIN_FILENO, &term ) < 0 ) {
		fprintf( stderr, "tcgetattr error.\n" );
		exit( 0 );
	}

	term.c_cc[VINTR] = vdisable;
	term.c_cc[VEOF] = 2; // EOF is Control - B

	if( tcsetattr( STDIN_FILENO, TCSAFLUSH, &term ) < 0 ) {
		fprintf( stderr, "tcsetattr error.\n" );
		exit( 0 );
	}

	test_read_write();

	return 0;
}
